package cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpwestlistdx;

import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpwestlistdx.vo.DpWestListDxPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpwestlistdx.vo.DpWestListDxRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpwestlistdx.vo.DpWestListDxSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.dplist.DpWestListDxDO;
import cn.iocoder.yudao.module.erp.service.dpwest.DpWestListDxService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import java.io.IOException;
import java.util.List;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;


@Tag(name = "管理后台 - 东线口岸仓西线清单")
@RestController
@RequestMapping("/erp/dp-west-list-dx")
@Validated
public class DpWestListDxController {

    @Resource
    private DpWestListDxService dpWestListDxService;

    @PostMapping("/create")
    @Operation(summary = "创建东线口岸仓西线清单")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-dx:create')")
    public CommonResult<Long> createDpWestListDx(@Valid @RequestBody DpWestListDxSaveReqVO createReqVO) {
        return success(dpWestListDxService.createDpWestListDx(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新东线口岸仓西线清单")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-dx:update')")
    public CommonResult<Boolean> updateDpWestListDx(@Valid @RequestBody DpWestListDxSaveReqVO updateReqVO) {
        dpWestListDxService.updateDpWestListDx(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除东线口岸仓西线清单")
    @Parameter(name = "id", description = "编号", required = true)
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-dx:delete')")
    public CommonResult<Boolean> deleteDpWestListDx(@RequestParam("id") Long id) {
        dpWestListDxService.deleteDpWestListDx(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得东线口岸仓西线清单")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-dx:query')")
    public CommonResult<DpWestListDxRespVO> getDpWestListDx(@RequestParam("id") Long id) {
        DpWestListDxDO dpWestListDx = dpWestListDxService.getDpWestListDx(id);
        return success(BeanUtils.toBean(dpWestListDx, DpWestListDxRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得东线口岸仓西线清单分页")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-dx:query')")
    public CommonResult<PageResult<DpWestListDxRespVO>> getDpWestListDxPage(@Valid DpWestListDxPageReqVO pageReqVO) {
        PageResult<DpWestListDxDO> pageResult = dpWestListDxService.getDpWestListDxPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DpWestListDxRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出东线口岸仓西线清单 Excel")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-dx:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportDpWestListDxExcel(@Valid DpWestListDxPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DpWestListDxDO> list = dpWestListDxService.getDpWestListDxPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "东线口岸仓西线清单.xls", "数据", DpWestListDxRespVO.class,
                        BeanUtils.toBean(list, DpWestListDxRespVO.class));
    }

}